 package com.gmrz.uaf.crypto;
 
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import com.google.inject.name.Named;
 import com.gmrz.util.Convert;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Properties;
 
 @Singleton
 public class CryptoConfig
 {
   static final String UAF_CUSTOM_CRYPTO_IMPL_CLASS_NAME = "uaf.crypto.custom.impl.class.name";
   static final String UAF_JCE_PROVIDERS = "uaf.jce.providers";
   static final String UAF_DEFAULT_EXTERNAL_ENCRYPTION_KEY_ALGO = "uaf.default.external.encryption.key.algo";
   static final String UAF_DEFAULT_EXTERNAL_HMAC_KEY_ALGO = "uaf.default.external.hmac.key.algo";
   static final String UAF_DEFAULT_EXTERNAL_ENCRYPTION_TRANSFORMATION = "uaf.default.external.encryption.transformation";
   static final String UAF_DEFAULT_EXTERNAL_ENCRYPTION_KEY = "uaf.default.external.encryption.key";
   private byte[] defaultExternalEncryptionKey = null;
 
   private String defaultExternalEncryptionTransformation = null;
 
   private String defaultExternalEncryptionKeyAlgo = null;
 
   private String defaultExternalHmacKeyAlgo = null;
   private String cryptoCustomClassName;
   private String jceProviders = null;
   private Properties customProperties;
   static final String UAF_CUSTOM_CRYPTO_PROPERTIES_NAMED_BINDING = "uaf.custom.crypto.properties";
 
   public static Collection<? extends String> getAllConfigurations()
   {
     return Arrays.asList(UAF_DEFAULT_EXTERNAL_ENCRYPTION_KEY, UAF_DEFAULT_EXTERNAL_ENCRYPTION_TRANSFORMATION,
             UAF_DEFAULT_EXTERNAL_ENCRYPTION_KEY_ALGO, UAF_DEFAULT_EXTERNAL_HMAC_KEY_ALGO, UAF_JCE_PROVIDERS,
             UAF_CUSTOM_CRYPTO_IMPL_CLASS_NAME);
   }
 
   public byte[] getExternalEncryptionKey()
   {
     return this.defaultExternalEncryptionKey;
   }
 
   public String getExternalEncryptionTransformation() {
     return this.defaultExternalEncryptionTransformation;
   }
 
   public String getExternalEncryptionKeyAlgo() {
     return this.defaultExternalEncryptionKeyAlgo;
   }
 
   public String getExternalHmacKeyAlgo() {
     return this.defaultExternalHmacKeyAlgo;
   }
 
   public String getCryptoServiceClassName() {
     return this.cryptoCustomClassName;
   }
 
   public String getJceProviders() {
     return this.jceProviders;
   }
 
   public Properties getCustomProperties() {
     return this.customProperties;
   }
 
   @Inject
   private void setEncryptionAlgoName(@Named("uaf.default.external.encryption.transformation") String transformation)
   {
     this.defaultExternalEncryptionTransformation = transformation;
   }
 
   @Inject
   private void setEncryptionKey(@Named("uaf.default.external.encryption.key") String key)
   {
     if (key != null)
       this.defaultExternalEncryptionKey = Convert.fromBase64(key);
   }
 
   @Inject
   private void setEncryptionKeyAlgo(@Named("uaf.default.external.encryption.key.algo") String keyAlgo)
   {
     this.defaultExternalEncryptionKeyAlgo = keyAlgo;
   }
 
   @Inject
   private void setHmacKeyAlgo(@Named("uaf.default.external.hmac.key.algo") String keyAlgo)
   {
     this.defaultExternalHmacKeyAlgo = keyAlgo;
   }
 
   @Inject
   private void setJceProviders(@Named("uaf.jce.providers") String jceProviders)
   {
     this.jceProviders = jceProviders;
   }
 
   @Inject
   private void setCryptoCustomClassName(@Named("uaf.crypto.custom.impl.class.name") String className)
   {
     this.cryptoCustomClassName = className;
   }
 
   @Inject
   private void setCryptoCustomProperties(@Named("uaf.custom.crypto.properties") Properties customProperties)
   {
     this.customProperties = customProperties;
   }
 }
